<template>
	<view>
		<view class="header">
			<view class="item" :class="tabIndex == index?'active':''" @click="handleStatus(index)"
				v-for="(item,index) in statusList" :key="index">
				{{item.name}}
			</view>
		</view>
		<view class="list">
			<view class="phone" v-for="(item,index) in list" :key="index">

				<view class="item">
					<view class="label">
						学员电话：
					</view>
					<view class="value">
						{{item.mobile}}
					</view>
				</view>
				<view class="item">
					<view class="label">
						申请时间：
					</view>
					<view class="value">
						{{item.createdtime}}
					</view>
				</view>
				<view class="item">
					<view class="label">
						学员来源：
					</view>
					<view class="value">
						{{item.org}}
					</view>
				</view>
				<view class="operate" v-if="item.is_contact === 0">
					<view class="btn" type="primary" @click="callPhone(item)">拨打</view>
					<view class="btn" type="primary" @click="finishContact(item)">已联系</view>
				</view>
			</view>
		</view>
		<u-empty v-if="list.length == 0" mode="data" icon="http://cdn.uviewui.com/uview/empty/car.png">
		</u-empty>
		<u-modal v-model="show" title="登录" @confirm="confirmModal" :show-cancel-button="true" cancel-text="取消"
			confirm-text="登录" @cancel="cancel">
			<login ref="login"></login>
		</u-modal>
	</view>
</template>

<script>
	import {
		studenListApi,
		callPhoneConfirm
	} from "@/api/index.js"
	import login from "./simulationLogin.vue"
	export default {
		components: {
			login
		},
		data() {
			return {
				show: false,
				list: [],
				page: 1,
				finish: false,
				statusList: [{
					name: '未联系',
					id: '0'
				}, {
					name: '已联系',
					id: '1'
				}],
				tabIndex: 0,
				status: 0,
				studentList: [],
				mobile: ''
			};
		},
		onShow() {
			let mobile = uni.getStorageSync("yPhone")
			if (mobile) {
				this.mobile = mobile
				this.getSdutendList()
			} else {
				this.show = true
			}

		},
		methods: {
			//拨打电话
			callPhone(item) {
				uni.makePhoneCall({
					phoneNumber: item.mobile //仅为示例
				});
			},
			//已联系
			finishContact(item, index) {
				callPhoneConfirm({
					id: item.id
				}).then(res => {
					if (res.code == 1) {
						this.list.splice(index, 1)
					}
				})
			},
			//学员列表
			getSdutendList() {

				let params = {
					teacher_mobile: this.mobile,
					page: this.page,
					is_contact: this.status,
					page_size: 20
				}
				studenListApi(params).then(res => {
					uni.stopPullDownRefresh();
					if (res.code == 1) {
						let list = res.data.list

						if (this.page == 1) {
							this.list = list
							this.finish = false
						} else {
							this.list = this.list.concat(list)
						}
						if (list.length < 20) {
							this.finish = true
						}
						console.log(this.list)
					}
				})
			},
			confirmModal() {
				// console.log('open');
				this.$refs.login.getGister()
			},
			cancel() {
				this.show = false
				// console.log('close');
			},
			// 切换状态
			handleStatus(index) {
				console.log(index)
				this.status = index
				this.tabIndex = index
				this.getSdutendList()
			}
		},
		//下拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.getSdutendList()

		},
		//上拉加载更多
		onReachBottom() {
			if (!this.finish) {
				this.page = this.page + 1
				this.getSdutendList()
			}

		},
	}
</script>

<style lang="scss">
	.header {
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #fff;

		.item {
			color: #606266;
			font-size: 26rpx;
			height: 80rpx;
			position: relative;
			flex: 1;
			text-align: center;
			line-height: 80rpx;
		}

		.active {
			color: #222;
		}

		.active::after {
			content: '';
			position: absolute;
			bottom: 0;
			left: 50%;
			margin-left: -15px;
			width: 30px;
			height: 2px;
			background-color: #2979ff;
			border-radius: 10px;
		}
	}

	.list {

		margin-top: 20rpx;
		padding: 0 26rpx;

		.phone {
			background-color: #fff;
			padding: 26rpx;
			border-radius: 10rpx;

			.item {
				color: #969696;
				font-size: 28rpx;
				font-weight: 400;
				margin-top: 10rpx;
				display: flex;


				.label {
					width: 150rpx;
					color: #666;
				}

				.value {
					color: #333;
				}
			}

			.operate {
				display: flex;
				align-items: center;
				justify-content: flex-end;
				margin-top: 20rpx;

				.btn {
					background-color: #2979ff;
					margin-left: 20rpx;
					line-height: 60rpx;
					color: #fff;
					width: 140rpx;
					text-align: center;
					border-radius: 6rpx;
					font-size: 26rpx;
				}
			}
		}
	}
</style>